﻿using System.Net;

namespace ScreenWarnning
{
    public partial class FormLogin : Form
    {
        public CookieCollection CookieCollection { get; private set; }

        public FormLogin()
        {
            InitializeComponent();
        }

        private void picCode_Click(object sender, EventArgs e)
        {
            picCode.Image = GlobalContext.DataProvider.GetCode();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtUserName.Text))
            {
                MessageBox.Show("请输入用户名");
                return;
            }
            if (string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MessageBox.Show("请输入密码");
                return;
            }
            if (string.IsNullOrWhiteSpace(txtUserName.Text))
            {
                MessageBox.Show("请输入用户名");
                return;
            }

            try
            {
                GlobalContext.DataProvider.Login(txtUserName.Text, txtPassword.Text, txtCode.Text);

                new FormMain().Show();
                this.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            picCode.Image = GlobalContext.DataProvider.GetCode();
        }

        private void FormLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
